package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.BaseVo;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.Bed;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.mapper.NursingPlanMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingProject;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Description NursingLevelServiceImpl
 * @Author zpf
 * @Date 2024-08-27
 */
@Service
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    /**
     * 3.1 查询所有护理等级
     */
    @Override
    public List<NursingLevelVo> listAll() {
        return nursingLevelMapper.listAll();
    }

    //    新增护理等级
    @Override
    public void insert(NursingLevelDto nursingLevel) {
        NursingLevel level = BeanUtil.toBean(nursingLevel, NursingLevel.class);
        nursingLevelMapper.insert(level);
    }

    //    3.3 条件分页查询
    @Override
    public PageResponse<NursingLevelVo> getByPage(
            String name, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingLevelVo> page = nursingLevelMapper.selectByPage(name, status);
        PageResponse<NursingLevelVo> pageResponse = new PageResponse(page);
        pageResponse.setRecords(page.getResult());
        return pageResponse;
    }

    // 根据id获取护理等级数据
    @Override
    public NursingLevelVo getById(Long id) {
        return BeanUtil.toBean(nursingLevelMapper.getById(id), NursingLevelVo.class);
    }

//3.5 修改护理等级
    @Override
    public void updateNursingLevel(NursingLevelDto nursingLevelDto) {
        NursingLevel level = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.update(level);

    }
//3.6 删除
    @Override
    public void deleteNursingLevel(Long id) {
        nursingLevelMapper.delete(id);
    }
//    启用禁用
    @Override
    public void ResetStatus(Long id, int status) {
        nursingLevelMapper.updateStatus(id, status);

    }
    // 批量插入护理等级数据
    @Override
    public void insertBatch(List<NursingLevelDto> nursingLevels) {
        List<NursingLevel> levels = BeanUtil.copyToList(nursingLevels, NursingLevel.class);
        nursingLevelMapper.insertBatch(levels);
    }

}
